//
//  ImageShowScroll.m
//  UIDemo
//
//  Created by Eason on 2017/4/21.
//  Copyright © 2017年 eason. All rights reserved.
//

#import "ImageShowScroll.h"
@interface ImageShowScroll()
@property (nonatomic, readonly)UIImage *showImg;
@property (nonatomic, readonly)CGRect originImgRect;
@property (nonatomic, readonly)CGRect showImageViewRect;
@end
@implementation ImageShowScroll

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(instancetype)initWithFrame:(CGRect)frame image:(UIImage*)aImage{
    self =[super initWithFrame:frame];
    if (self) {
        [self setScrollImage:aImage];
    }
    return self;
}

-(void)setScrollImage:(UIImage*)image{
    _showImg=image;
    _originImgRect=CGRectMake(0, 0, image.size.width, image.size.height);
    if (_showImg) {
        CGSize size=_showImg.size;
        UIImageView *imgView=[[UIImageView alloc]initWithImage:_showImg];
        CGFloat height=size.height*ScreenWidth/size.width;
        CGRect rect=CGRectMake(-2.5, 0, ScreenWidth, height);
        [imgView setFrame:rect];
        
        [self addSubview:imgView];
        self.contentSize=rect.size;
        _showImageViewRect=imgView.frame;
    }
    
}
-(CGRect)originImageFrame{
    return _originImgRect;
}
-(CGRect)showImageFrame{
    return _showImageViewRect;
}

@end
